package com.nsn.das.midas.report;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import com.nsn.das.midas.model.mml.data.MasterListData;

public abstract class GenerateFile {
	protected static final String WORD_WRAP = "/r/n";
	protected File file;
	protected FileOutputStream fos;
	
	protected List<String> listHead=new ArrayList<String>();
	protected List<String> listBody=new ArrayList<String>();
	protected List<String> listTail=new ArrayList<String>();
	protected MasterListData masterListData;
	protected abstract String getOutPutFileName();	
	protected void createFile(MasterListData masterListData ){		
		//file=new File("c:\\tmp\\"+fileName);
		file = new File(getOutPutFileName());
		try {
			file.createNewFile();
			fos=new FileOutputStream(file);	
			fos.write(getHeader().getBytes());
			fos.write(getBody().getBytes());
			fos.write(getTail().getBytes());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}			
	}
	protected abstract String getHeader();
	protected abstract String getBody();
	protected abstract String getTail();	
	/*protected void appendStarHeader(String content){
		content += "/*********";
		appendWordWrap(content);
	}*/
	protected String appendWordWrap(String content){
		return content+WORD_WRAP;
	}
	protected String Spc(int number){
		char[] data=new char[number];
		for(int i=0;i<number;i++){
			data[i]=' ';
		}
		return String.valueOf(data);
	}
	protected String getTime(){
		String[] month={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
		Calendar c=Calendar.getInstance();
		return String.valueOf(c.get(Calendar.DATE))+" "+month[c.get(Calendar.MONTH-1)]+" "+
				String.valueOf(c.get(Calendar.YEAR));
	}
	protected String formatGroupName(String name){
		if(name.charAt(0)=='0'){
			return name.substring(1).toLowerCase();
		}else{
			return name;
		}
	}
	protected String turnListToString(List<String> list){
		StringBuffer sb=new StringBuffer();
		for(String l:list){
			sb.append(appendWordWrap(l));
		}
		return sb.toString();
	}
}
